var webpack = require('webpack');
// var CSSSplitWebpackPlugin = require('css-split-webpack-plugin/dist/index').default;
var ImageminPlugin = require('imagemin-webpack-plugin').default
// const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const CompressionPlugin = require("compression-webpack-plugin");
module.exports = function(webpackConfig, env) {
// adding plugins to your configuration
    webpackConfig.plugins.push( 
        // new CSSSplitWebpackPlugin({
        //     size: 2000,
        //     imports:true
        // }),
        new ImageminPlugin({
            disable: process.env.NODE_ENV !== 'production', 
            pngquant: {
              quality: '95-100'
            }
          }),

        //   new UglifyJSPlugin({
        //     parallel: 4,
        //     uglifyOptions: {
        //         output: {
        //             comments: false,
        //             beautify: false,
        //         },
        //         compress: {
        //             warnings: false
        //         },
        //     },
        //     cache: true,
        // }),

          new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: JSON.stringify(process.env.NODE_ENV),
            },
          }),
          new CompressionPlugin({
            asset: '[path].gz[query]', //目标资源名称。[file] 会被替换成原资源。[path] 会被替换成原资源路径，[query] 替换成原查询字符串
            algorithm: 'gzip',//算法
            test: new RegExp(
                 '\\.(js|css)$'    //压缩 js 与 css
            ),
            threshold: 10240,//只处理比这个值大的资源。按字节计算
            minRatio: 0.8//只有压缩率比这个值小的资源才会被处理
       }),
    //    new HtmlWebpackPlugin({
    //     title: '',
    //        template: __dirname + '/../public/index.html',
    //        minify: {
    //            removeComments: true,
    //            collapseWhitespace: true,
    //            removeRedundantAttributes: true,
    //            useShortDoctype: true,
    //            removeEmptyAttributes: true,
    //            removeStyleLinkTypeAttributes: true,
    //            keepClosingSlash: true,
    //            minifyJS: true,
    //            minifyCSS: true,
    //            minifyURLs: true,
    //        },
    //        chunksSortMode:'dependency'
    //    }),



         
    )
    
    return webpackConfig
}